﻿Imports Global_Visas_Business_Layer
Partial Public Class frmReportForm



    Private Function ValidateUI() As Boolean ' Handles Me.Loaded, txtConID.KeyUp, txtConName.KeyUp, txtSubject.KeyUp, txtDescription.KeyUp, cboPriority.SelectionChanged
        If txtConID.Text <> String.Empty Then
            If txtConName.Text <> String.Empty Then
                If txtSubject.Text <> String.Empty Then
                    If txtDescription.Text <> String.Empty Then
                        If cboPriority.Text <> String.Empty Then
                            btnSend.IsEnabled = True
                            Return True
                        Else
                            btnSend.IsEnabled = False
                            Return False
                        End If
                    Else
                        btnSend.IsEnabled = False
                        Return False
                    End If
                Else
                    btnSend.IsEnabled = False
                    Return False
                End If
            Else
                btnSend.IsEnabled = False
                Return False
            End If
        Else
            btnSend.IsEnabled = False
            Return False
        End If
    End Function

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSend.Click
        'Create incident
        If ValidateUI() Then
            Dim IncidentNo As Long
            Dim priority As IT.IncidentPriority
            Select Case cboPriority.Text
                Case "Very High"
                    priority = IT.IncidentPriority.VeryHigh
                Case "High"
                    priority = IT.IncidentPriority.High
                Case "Medium"
                    priority = IT.IncidentPriority.Medium
                Case "Low"
                    priority = IT.IncidentPriority.Low
            End Select
            IncidentNo = CLng(IT.CreateNewIncident(CLng(txtConID.Text.Trim), txtConName.Text.Trim, txtSubject.Text.Trim, txtDescription.Text.Trim, txtInternalNotes.Text.Trim, priority))
            If IncidentNo > 0 Then
                btnSend.IsEnabled = False
                MsgBox("The incident has been created and sent to IT. You would receive an email shortly" & vbCrLf & vbCrLf & "Incident Number : " & IncidentNo & vbCrLf & vbCrLf & "Please quote this incident number for future references", MsgBoxStyle.Information, "Incident")
            Else
                btnSend.IsEnabled = True
            End If
            'send email to the incident raiser

            'Display incident reference number
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        If btnSend.IsEnabled = True Then
            If MsgBox("Would you want to close the screen without reporting to IT? ", MsgBoxStyle.YesNo, "Close?") = MsgBoxResult.Yes Then
                Me.Close()
            Else
            End If
        Else
            Me.Close()
        End If
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnNew.Click
        txtConID.Text = String.Empty
        txtConName.Text = String.Empty
        txtDescription.Text = String.Empty
        txtInternalNotes.Text = String.Empty
        txtSubject.Text = String.Empty
        cboPriority.SelectedIndex = -1
    End Sub

    Private Sub frmReportForm_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        txtConID.Text = GlobalCRM.CurrentConID
        txtConName.Text = GlobalCRM.CurrentConName
    End Sub
End Class


